package com.cust.yx.controller;

import com.cust.yx.client.ProductFeignClient;
import com.cust.yx.common.auth.AuthContextHolder;
import com.cust.yx.common.result.Result;
import com.cust.yx.model.product.Category;
import com.cust.yx.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "首页接口")
@RestController
@RequestMapping("/home")
public class HomeApiController {

    @Autowired
    private HomeService homeService;

    @Autowired
    private ProductFeignClient productFeignClient;

    @ApiOperation("首页数据显示接口")
    @GetMapping("/index")
    public Result index() {
        Long userId = AuthContextHolder.getUserId();
        Map<String,Object> map = homeService.homeData(userId);
        return Result.ok(map);
    }

    @ApiOperation("所有商品分类")
    @GetMapping("/category")
    public Result categoryList() {
        List<Category> categoryList = productFeignClient.findAllCategoryList();
        return Result.ok(categoryList);
    }




}
